<template>
  <div class="listener-config">
    <el-form label-width="120px" class="sub-form">
      <el-form-item label="监听器">
        <el-button size="default" @click="addListener">添加监听器</el-button>
      </el-form-item>
      <div v-for="(listener, idx) in listeners" :key="idx" style="margin-bottom:8px;">
        <el-form-item label="事件">
          <el-select v-model="listener.event" placeholder="事件" @change="onChange">
            <el-option label="创建" value="create" />
            <el-option label="分配" value="assign" />
            <el-option label="完成" value="complete" />
            <el-option label="删除" value="delete" />
          </el-select>
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="listener.type" placeholder="类型" @change="onChange">
            <el-option label="内置" value="builtin" />
            <el-option label="自定义" value="custom" />
          </el-select>
        </el-form-item>
        <el-form-item label="类名">
          <el-input v-model="listener.class" placeholder="监听器类名" @input="onChange" />
        </el-form-item>
        <el-button type="danger" size="default" @click="removeListener(idx)">删除</el-button>
      </div>
    </el-form>
  </div>
</template>

<script setup>
const props = defineProps({
  listeners: Array
})

const emit = defineEmits(['change'])

/**
 * 添加监听器
 */
function addListener() {
  props.listeners.push({event:'',type:'',class:''})
  emit('change')
}

/**
 * 删除监听器
 */
function removeListener(idx) {
  props.listeners.splice(idx, 1)
  emit('change')
}

/**
 * 处理变更
 */
function onChange() {
  emit('change')
}
</script>

<style scoped>
.listener-config {
  width: 100%;
}

.sub-form .el-form-item {
  margin-bottom: 10px;
}

.sub-form .el-form-item__label {
  color: #b1b3b8;
  font-size: 13px;
}
</style> 